home *** CD-ROM | disk | FTP | other *** search
- var ds, container, styleCount, enumerator, progress, numberDone, style;
- function init() {
- ds = GoogleRedesignedStyle.prototype.ds;
- container = ds.getNode(GoogleRedesignedStyle.prototype.containerURI);
- styleCount = container.getChildCount();
- enumerator = ds.getAllResources();
- progress = document.getElementById("progress");
- numberDone = 0;
- repairNext();
- }
- function repairNext() {
- if (!enumerator.hasMoreElements()) {
- ds.save();
- close();
- return;
- }
- var node = enumerator.getNext();
- if (node.source.Value == container.source.Value) {
- repairNext();
- return;
- }
- if (container.getChildIndex(node) == -1) {
- ds.deleteRecursive(node);
- repairNext();
- return;
- }
- style = new GoogleRedesignedStyle(node);
- if (!style.code) {
- ds.deleteRecursive(style.node);
- numberDone++;
- progress.setAttribute("value", (0 + numberDone) / styleCount * 100 + "%");
- repairNext();
- return;
- }
- if (style.updateURL) {
- if (/http:\/\/userstyles.org\/style\/show\/[0-9]+\?raw/.test(style.updateURL)) {
- style.updateURL = style.updateURL.replace("/style/", "/styles/").replace("/show/", "/").replace("?raw", ".css");
- style.save();
- } else if (/http:\/\/userstyles.org\/style\/raw\/[0-9]+/.test(style.updateURL)) {
- style.updateURL = style.updateURL.replace("/style/", "/styles/").replace("/raw/", "/") + ".css";
- style.save();
- } else if (/http:\/\/userstyles.org\/styles\/raw\/[0-9]+/.test(style.updateURL)) {
- style.updateURL = style.updateURL.replace("/raw/", "/") + ".css";
- style.save();
- }
- }
- if (/http:\/\/userstyles.org\/style\/show\/[0-9]+/.test(style.uri)) {
- var newStyle = new GoogleRedesignedStyle(style.uri.replace("/style/", "/styles/").replace("/show/", "/"));
- style.copy(newStyle);
- GoogleRedesignedStyle.prototype.ds.deleteRecursive(style.node);
- newStyle.save();
- repairNext();
- return;
- }
- check();
- }
- function check() {
- var doc = document.implementation.createDocument(googleredesignedCommon.XULNS, "googleredesigned-parse", null);
- var link = doc.createElementNS(googleredesignedCommon.HTMLNS, "link");
- link.rel = "stylesheet";
- link.type = "text/css";
- link.href = googleredesignedCommon.codePrefix + style.code;
- var loadedListener = new GoogleRedesignedStylesheetLoadedListener(doc, null, loaded);
- doc.documentElement.appendChild(link);
- loadedListener.checkStyleLoaded();
- }
- function loaded(success, data) {
- style.calculateMetadata(data.stylesheet);
- numberDone++;
- progress.setAttribute("value", (0 + numberDone) / styleCount * 100 + "%");
- repairNext();
- }